package com.zeyi.blog.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zeyi.blog.util.Tree;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 文章评论表(Comment)表实体类
 *
 * @author 黎先森
 * @since 2020-07-31 15:32:09
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Comment implements Serializable, Tree<Comment> {
    private static final long serialVersionUID = 1L;
    //ID
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    //文章ID
    private String articleId;
    //上级评论ID
    private String pid;
    //评论人ID
    private String fromUserId;
    //被评论人ID
    private String toUserId;
    //评论内容
    private String content;
    //评论时间
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @TableField(exist = false)
    private String toUsername;
    @TableField(exist = false)
    private String toUserAvatar;
    @TableField(exist = false)
    private String fromUsername;
    @TableField(exist = false)
    private String fromUserAvatar;
    @TableField(exist = false)
    private List<Comment> children;

    @JsonIgnore
    @Override
    public String getParentId() {
        return pid;
    }

    @Override
    public void setChildren(List<Comment> children) {
        this.children = children;
    }

    @Override
    public List<Comment> getChildren() {
        return children;
    }
}